﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraBars;
using System.Threading;
using DevExpress.XtraEditors;
using VOL;
using BLL;

namespace Shopper
{
    public partial class frmMain : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        private frmDMKhachManager _frmDMKhachManager;
        private frmHangHoaManager _frmHangHoaManager;
        private frmLoaiHangManager _frmLoaiHangManager;
        private frmNguoiDungManager _frmNguoiDungManager;
        private frmNhaCungCapManager _frmNhaCungCapManager;
        private frmShopping _frmShopping;
        private frmAbout _frmAbout;
        private frmSupport _frmSupport;
        private frmReport _frmReport;
        private frmBieuDo _frmBieuDo;
        private NguoiDung _nguoiDung = new NguoiDung();

        public frmMain(NguoiDung nguoidung)
        {
            InitializeComponent();
            this._nguoiDung = nguoidung;
            lblHoTen.Caption = _nguoiDung.HoTen;
        }

        private void frmMain_Load(object sender, EventArgs e)
        {

        }

        private void btnBanHang_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (_frmShopping == null)
            {
                _frmShopping = new frmShopping();
                ///////////////////
                _frmShopping.MdiParent = this;
                _frmShopping.Show();
            }
            else
            {
                _frmShopping.Activate();
            }
        }

        private void btnNhaCungCap_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (_frmNhaCungCapManager == null)
            {
                _frmNhaCungCapManager = new frmNhaCungCapManager();
                _frmNhaCungCapManager.MdiParent = this;
                _frmNhaCungCapManager.Show();
            }
            else
            {
                _frmNhaCungCapManager.Activate();
            }
        }

        private void btnLoaiHang_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (_frmLoaiHangManager == null)
            {
                _frmLoaiHangManager = new frmLoaiHangManager();
                _frmLoaiHangManager.MdiParent = this;
                _frmLoaiHangManager.Show();
            }
            else
            {
                _frmLoaiHangManager.Activate();
            }
        }

        private void btnNguoiDung_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (_frmNguoiDungManager == null)
            {
                _frmNguoiDungManager = new frmNguoiDungManager();
                _frmNguoiDungManager.MdiParent = this;
                _frmNguoiDungManager.Show();
            }
            else
            {
                _frmNguoiDungManager.Activate();
            }
        }

        private void btnKhachHang_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (_frmDMKhachManager == null)
            {
                _frmDMKhachManager = new frmDMKhachManager();
                _frmDMKhachManager.MdiParent = this;
                _frmDMKhachManager.Show();
            }
            else
            {
                _frmDMKhachManager.Activate();
            }
        }

        private void btnHangHoa_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (_frmHangHoaManager == null)
            {
                _frmHangHoaManager = new frmHangHoaManager();
                _frmHangHoaManager.MdiParent = this;
                _frmHangHoaManager.Show();
            }
            else
            {
                _frmHangHoaManager.Activate();
            }
        }

        private void btnChangePass_ItemClick(object sender, ItemClickEventArgs e)
        {
            using (frmChangePwd frm = new frmChangePwd())
            {
                if (frm.ShowDialog(this.FindForm()) == System.Windows.Forms.DialogResult.Yes)
                {
                    string PassOld = frm.PassOld;
                    string PassNew = frm.PassNew;
                    string PassNewComfirm = frm.PassNewConfirm;

                    if (PassOld == _nguoiDung.MatKhau)
                    {
                        _nguoiDung.MatKhau = PassNew;
                        NguoiDungBL nguoidungBl = new NguoiDungBL();
                        nguoidungBl.ChangPass(_nguoiDung);
                        DialogResult dr = XtraMessageBox.Show("Đã đổi mật khẩu thành công", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        DialogResult dr = XtraMessageBox.Show("Mật khẩu cũ chưa chính xác", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }

        private void btnExit_ItemClick(object sender, ItemClickEventArgs e)
        {
            DialogResult dr = XtraMessageBox.Show("Bạn muốn thoát khỏi phần mềm hay không?", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (dr == System.Windows.Forms.DialogResult.Yes)
            {
                Application.Exit();
            }
        }

        private void btnHelp_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (_frmSupport == null)
            {
                _frmSupport = new frmSupport();
                _frmSupport.MdiParent = this;
                _frmSupport.Show();
            }
            else
            {
                _frmSupport.Activate();
            }
        }

        private void btnAbout_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (_frmAbout == null)
            {
                _frmAbout = new frmAbout();
                _frmAbout.MdiParent = this;
                _frmAbout.Show();
            }
            else
            {
                _frmAbout.Activate();
            }
        }

        private void btnDangXuat_ItemClick(object sender, ItemClickEventArgs e)
        {
            
        }

        private void btnReport_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (_frmReport == null)
            {
                _frmReport = new frmReport();
                _frmReport.MdiParent = this;
                _frmReport.Show();
            }
            else
            {
                _frmReport.Activate();
            }
        }

        private void btnChart_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (_frmBieuDo == null)
            {
                _frmBieuDo = new frmBieuDo();
                _frmBieuDo.MdiParent = this;
                _frmBieuDo.Show();
            }
            else
            {
                _frmBieuDo.Activate();
            }
        }
    }
}